package com.shopping.shoppingdemo.domain.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shopping.shoppingdemo.domain.po.RequestCountDO;
import com.shopping.shoppingdemo.domain.vo.PageParam;
import com.shopping.shoppingdemo.mapper.RequestCountMapper;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

import static com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery;

@Repository
public class RequestCountDao extends ServiceImpl<RequestCountMapper, RequestCountDO> {

//    public Long getPvTotalCount() {
//        return baseMapper.getPvTotalCount();
//    }

    /**
     * 获取请求数据
     *
//     * @param host
//     * @param date
     * @return
     */
//    public RequestCountDO getRequestCount(String host, Date date) {
//        return lambdaQuery()
//                .eq(RequestCountDO::getHost, host)
//                .eq(RequestCountDO::getDate, date)
//                .one();
//    }

    public List<RequestCountDO> listRequestCount(PageParam pageParam) {
        LambdaQueryWrapper<RequestCountDO> query = Wrappers.lambdaQuery();
        query.orderByDesc(RequestCountDO::getId);
        if (pageParam != null) {
            query.last(PageParam.getLimitSql(pageParam));
        }
        return baseMapper.selectList(query);
    }

    /**
     * 获取 PV UV 数据列表
     * @param day
     * @return
     */
    public List<StatisticsDayDTO> getPvUvDayList(Integer day) {
        return baseMapper.getPvUvDayList(day);
    }

//    public void incrementCount(Long id) {
//        baseMapper.incrementCount(id);
//    }
}
